<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="f" uri="http://www.itcms.com/tags/form"%>
<%@page import="EIAC.EAC.SSO.AppSSOBLL,EIAC.EAC.SSO.ReadConfig,java.util.ResourceBundle"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none" />
<title>Itcms管理平台登录 - Powered by Itcms</title>
<script type="text/javascript">
//if(top!=this){top.location=this.location;}
</script>
<jsp:include page="/WEB-INF/views/commons/head.jsp"></jsp:include>
<script type="text/javascript">
//后台首页需显示在顶层框架中
if(top!=this){top.location=this.location;}

$(function() {
	$("#validForm").validate();
	$("#username").focus().select();
});

<c:if test="${!empty shiroLoginFailure}">
	<c:choose>
	<c:when test="${shiroLoginFailure=='com.itcms.common.security.IncorrectCaptchaException'}">
	  alert("<s:message code='incorrectCaptchaError'/>");
	</c:when>
	<c:when test="${shiroLoginFailure=='com.itcms.common.security.CaptchaRequiredException'}">
	  //do nothing
	</c:when>
	<c:otherwise>
	  alert("<s:message code='usernameOrPasswordError'/>");
	</c:otherwise>
	</c:choose>
</c:if>
</script>
<style type="text/css">
.center {
	margin: 0 auto;
	width: 800px;
}

.clear {
	clear: both;
}

.div1 {
	margin-top: 150px;
	padding-top: 5px;
	background: url('${ctx}/static/back/images/login_bg.png') no-repeat
		430px top;
}

.desc {
	float: left;
	height: 180px;
	width: 430px;
	padding-top: 40px;
	text-align: center;
	color: #858585;
	font-size: 28px;
	font-weight: bold;
	background: url('${ctx}/static/back/images/admin_logo.png') no-repeat
		center 8px;
}

.input_form {
	float: right;
	height: 180px;
	width: 370px;
}

.input_p {
	padding: 10px 0;
}

.input_p_submit {
	text-align: left;
	padding: 5px 0 5px 80px;
}

.label {
	display: block;
	float: left;
	width: 70px;
	padding-right: 10px;
	text-align: right;
	font-size: 14px;
	font-weight: bold;
	color: #666666;
}

.input {
	display: block;
	float: left;
	width: 180px;
}

.div2 {
	text-align: center;
	color: #555555;
}

a:link,a:visited {
	text-decoration: none;
	color: #014c90;
}

a:hover,a:active {
	text-decoration: underline;
	color: #014c90;
}
</style>
</head>
<body>
	<%
		String defUsername = com.itcms.core.constant.Constants.DEF_USERNAME;
		String defPassword = com.itcms.core.constant.Constants.DEF_PASSWORD;
		String username = (String) request.getAttribute("username");
		if (username != null) {
			defUsername = username;
		}
	%>
	<%
      String requestMethod=request.getMethod();
      requestMethod=requestMethod.toUpperCase();
      request.setCharacterEncoding("UTF-8");
      response.setCharacterEncoding("UTF-8");

	  
       //发送到EAC验证
         String posturl="";
         AppSSOBLL app=new AppSSOBLL();
         String IASID="";
		 String IASKey="";
         String TimeStamp="";
         String ReturnURL=request.getRequestURL().toString();//post 提交之后，认证系统返回的url
		 String SSOURL=""; 
		 String HECURL="";
         String UserAccount="";
         String Result="";
         String ErrorDescription="";
         String Authenticator="";
         if(request.getParameter("UserAccount")!=null) UserAccount=request.getParameter("UserAccount");
     	System.out.println(UserAccount);
         if(request.getParameter("Result")!=null) Result=request.getParameter("Result");
         if(request.getParameter("ErrorDescription")!=null) ErrorDescription=request.getParameter("ErrorDescription");
         if(request.getParameter("Authenticator")!=null) Authenticator=request.getParameter("Authenticator");
         if(request.getParameter("TimeStamp")!=null)TimeStamp=request.getParameter("TimeStamp");
         //取时间
         java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         java.util.Date currentTime = new java.util.Date();//得到当前系统时间
         String str_date1 = formatter.format(currentTime); //将日期时间格式化
       
         if(TimeStamp=="")TimeStamp=str_date1.toString(); 
         
		 //读配置文件

         EIAC.EAC.SSO.ReadConfig rd=new  EIAC.EAC.SSO.ReadConfig();
         IASKey=rd.getString("IASKey").toString();
		 IASID=rd.getString("IASID").toString();
         SSOURL=rd.getString("PostUrl").toString();
         ReturnURL=rd.getString("ReturnURL").toString();
		 

         //得到post的html 
         if(UserAccount==null||UserAccount=="")
         {         
			posturl=app.PostString1(IASID,TimeStamp,ReturnURL,null,SSOURL,IASKey); 	
// 			System.out.println(posturl); 
            out.print(posturl);    //post to EAC(SSO)
            UserAccount=request.getParameter("UserAccount");
            System.out.println(posturl); 
            System.out.println("UserAccount："+UserAccount); 
         }
        //结束properties
         
         //接收从EAC返回的
         if(UserAccount!=null&&UserAccount!="")
         {
            if(!Result.equals("0"))
                 {
                   out.print("Result验证不成功！"); 
                   out.print("IASID:"+IASID+", TimeStamp:"+TimeStamp+", UserAccount:"+UserAccount+", Result:"+Result+", ErrorDescription:"+ErrorDescription+", Authenticator:"+Authenticator);
                   return;
                 }
          
                if(app.ValidateFromEAC(IASID,TimeStamp,UserAccount,Result,ErrorDescription,Authenticator))
                 {
                  //to the protected page
                  //set cookies
                  Cookie  newCookie   =  new Cookie("UserAccount",UserAccount);   
                  response.addCookie(newCookie);
                  System.out.println(UserAccount);
                  response.sendRedirect("http://172.18.3.90:8080/hectest/sso_login_session.service");
                 }
				 else
                 {
					//to do 自身登陆
					response.sendRedirect("http://172.18.3.90:8080/hectest/login.service");
                 }
             
          }      
         
         //接收从
    %>
	<div class="center div1">
		<div class="desc">管理中心</div>
		<form id="validForm" action="login.do" method="post"
			class="input_form">
			<p class="input_p">
				<label for="username" class="label">用户名:</label> <input type="text"
					id="username" name="username" value="<%=defUsername%>"
					class="input required" />
				<div class="clear"></div>
			</p>
			<p class="input_p">
				<label for="password" class="label">密码:</label> <input
					type="password" id="password" name="password"
					value="<%=defPassword%>" class="input" />
				<div class="clear"></div>
			</p>
			<c:if
				test="${sessionScope.shiroCaptchaRequired || GLOBAL.captchaErrors<=0}">
				<p class="input_p">
					<label for="captcha" class="label">验证码:</label> <input type="text"
						id="captcha" name="captcha"
						class="input {required:true,remote:{url:'${ctx}/captcha.servlet',type:'post'},messages:{remote:'验证码错误'}}"
						autocomplete="off" />
					<div class="clear"></div>
				</p>
				<p class="input_p">
					<label for="captcha" class="label">&nbsp;</label> <img
						src="${ctx}/captcha.servlet"
						onclick="this.src='${ctx}/captcha.servlet?d='+new Date()*1"
						style="cursor: pointer; border: 1px solid #ccc;" title="点击重新获取验证码" />
					<div class="clear"></div>
				</p>
			</c:if>
			<p class="input_p_submit">
				<input type="submit" value="提交" />
			</p>
		</form>
		<div class="clear"></div>
	</div>
	<div class="center div2">
		&copy; 2010-2017 <a href="http://www.itcms.com/" target="_blank">Itcms</a>
		All Rights Reserved
	</div>

</body>
</html>